package com.job.DQH.dqh715.inClass;

public class StringCompare {
    public static void main(String[] args) {
        String name1 = "luck";
        String name2 = "lucy";
        System.out.println(name1.compareTo(name2));//返回值为前字符串一个字符一个字符减去后字符串的对应字符的ASCII码，直到其中一个字符串结束了

        String name3 = "luc";
        System.out.println(name1.compareTo(name3));//若长度不等，则返回1或-1

        System.out.println(name1+514.846);
        System.out.println(name1.concat(new String("494.4984")));//concat()方法，与+效果一致，实现字符串拼接（只能拼字符串）

        //contains()方法，查询字符串中是否有指定字符串
        String ur1 = "https://t.bilibili.com/?spm_id_from=333.1007.0.0";
        System.out.println(ur1.contains("https"));//T
        System.out.println(ur1.contains("46864dadsds"));//F

        //endWith()方法，查询字符串是否以指定字符串结尾，startsWith()同理
        System.out.println(ur1.endsWith("0.0"));//T
        System.out.println(ur1.startsWith("https://"));//T

        //indexof()方法：返回某字符或某字串在字符串中的首次出现下标，未出现则返回-1
        String ur2 = "https://pages.tmall.com/wow/a/act/tmall/dailygroup/199PT@1656411032@&bxsign=";
        System.out.println(ur2.indexOf("tmall"));//返回值为t的下标

        //练习：计算hello出现了多少次
        String ss = "ahellobhellochellohellohellohello";
        int findStart = 0;
        int count = 0;
        String find = "hello";
        while(ss.indexOf("hello",findStart)!=-1){
            count++;
            findStart = ss.indexOf("hello",findStart)+find.length();//每次循环从上次找到的位置+要找的字符串长度开始找
        }
        System.out.println(count);
    }
}
